import md5 from 'common/md5.js'
var userInfo="";
var UserToken="";
var timestamp = parseInt(new Date().getTime() / 1000);//精准到秒

/* 拼团小程序 配置 */
var appid="3SQh9NlhcuqiCaiZ";
var appSecret='CySmdsu8Uk6g5ylDi922wM4u4ChPJf8X';
var userInfo='';
var userPhone='';
var hasLogin=false;
var apiversion =1;
var Token ='';
var ptRequestHeader ="application/x-www-form-urlencoded";
var paramsBase ={
	appid:appid,
	api_version:apiversion,
	timestamp:timestamp,
}


/* 优家圈  配置*/
var ujqAppid ="wxfd6cbdf45aa01d05";
uni.setStorageSync('userInfo', userInfo);
uni.setStorageSync('Token', UserToken);
var ujqRequestHeader ="application/json;charset=utf-8";

//签名
/* var stringA ="appid="+appid+""+"&key="+appSecret+"";
var signA = md5(stringA).toUpperCase();
console.log(signA); 
 */
function sign(params) {
        let keys = [];
        for (let key in params) {  //取出对象里面的键  添加到数组中
            keys.push(key);
        }
        keys.sort();
        let string = '';
        for (let key in keys) {   // 根据排序好的进行重新赋值
            string += (keys[key] + '=' + params[keys[key]] + '&');
        }
        return md5(string + 'key=' + appSecret).toUpperCase();
    }

export default {
	    timestamp,//时间戳	
		appid,
		appSecret,
	    userInfo,
		userPhone,
		hasLogin,
		apiversion,
		Token,
		ujqAppid,
		ptRequestHeader,
		ujqRequestHeader,
		UserToken,
		sign:function(param) {
		        let keys = [];
		        for (let key in param) {  //取出对象里面的键  添加到数组中
		            keys.push(key);
		        }
		        keys.sort();
		        let string = '';
		        for (let key in keys) {   // 根据排序好的进行重新赋值
		            string += (keys[key] + '=' + param[keys[key]] + '&');
		        }
		        return md5(string + 'key=' + appSecret).toUpperCase();
		    }
}